package com.mogul.lahub

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

class MyItemDecoration(
    private val spaceH: Int,
    private val spaceV: Int
) :
    RecyclerView.ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        val position = parent.getChildAdapterPosition(view) + 1
        val dwjndw = spaceH / 3
        if (position <= 3) {
            if (position % 3 == 1) {
                outRect.left = 0
                outRect.right = dwjndw * 2
                outRect.top = 0
                outRect.bottom = 0
            } else if (position % 3 == 0) {
                outRect.left = dwjndw * 2
                outRect.right = 0
                outRect.top = 0
                outRect.bottom = 0
            } else {
                outRect.left = dwjndw
                outRect.right = dwjndw
                outRect.top = 0
                outRect.bottom = 0
            }
        }else {
            if (position % 3 == 1) {
                outRect.left = 0
                outRect.right = dwjndw * 2
                outRect.top = spaceV
                outRect.bottom = 0
            } else if (position % 3 == 0) {
                outRect.left = dwjndw * 2
                outRect.right = 0
                outRect.top = spaceV
                outRect.bottom = 0
            } else {
                outRect.left = dwjndw
                outRect.right = dwjndw
                outRect.top = spaceV
                outRect.bottom = 0
            }
        }
    }
}